package com.waji.controller;


import com.waji.entity.Line;
import com.waji.mapper.LineMapper;
import com.waji.service.LineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2020-12-02
 */
@RestController
@RequestMapping("/line")
public class LineController {

    @Autowired
    LineService lineService;
    @Autowired
    LineMapper lineMapper;

    @CrossOrigin
    @GetMapping("/showall")
    public Object showall(){
        return lineMapper.selectList(null);
    }

    @CrossOrigin
    @PostMapping("/update")
    public Object update(int id,double x1,double y1,double x2,double y2){
        Line line = new Line();
        line.setId(id);
        line.setX1(x1);
        line.setY1(y1);
        line.setX2(x2);
        line.setY2(y2);
        lineMapper.updateById(line);
        return lineMapper.selectById(id);
    }

    @CrossOrigin
    @PostMapping("/insertone")
    public Object insert(int id,double x1,double y1,double x2,double y2){
        Line line = new Line();
        line.setId(id);
        line.setX1(x1);
        line.setY1(y1);
        line.setX2(x2);
        line.setY2(y2);
        lineMapper.insert(line);
        return lineMapper.selectById(id);
    }

    @CrossOrigin
    @PostMapping("/deleteone")
    public String delete(int id){
        lineMapper.deleteById(id);
        return "删除成功";
    }
}
